package com.yanqu.road.server.cmd.strongholdwar.wild;

import com.yanqu.road.entity.activity.stronghold.StrongholdWildUserData;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.strongholdwar.CrossStrongholdMgr;
import com.yanqu.road.server.manager.strongholdwar.CrossStrongholdRankMgr;
import com.yanqu.road.server.pb.CrossStrongholdPb;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.C_CROSS_STRONGHOLD_WILD_LIST, desc = "获取据点列表信息")
public class CrossGetWildListCmd extends CrossUnionCommand {
    private int activityId;
    private long userId;
    private String unionUid;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        StrongholdWarProto.CrossStrongholdStatusReqMsg req = StrongholdWarProto.CrossStrongholdStatusReqMsg.parseFrom(packet.getBytes());
        activityId = req.getActivityId();
        userId = packet.getPlayerId();
        unionUid = req.getUnionUid();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        List<StrongholdWarProto.StrongholdFightStatusTempMsg.Builder> listData = CrossStrongholdMgr.getWildListData(activityId, groupId);
        StrongholdWarProto.CrossStrongholdStatusResp.Builder resp = StrongholdWarProto.CrossStrongholdStatusResp.newBuilder();
        //据点信息
        for (StrongholdWarProto.StrongholdFightStatusTempMsg.Builder wildMsg : listData) {
            resp.addStrongholdStatus(wildMsg);
        }
        StrongholdWildUserData wildUser = CrossStrongholdMgr.getWildUser(activityId, serverId, userId);
        //派遣门客信息
        if (wildUser != null) {
            StrongholdWarProto.StrongholdDispatchPatronsTempMsg.Builder wildUserMsg = CrossStrongholdPb.getWildUserMsg(wildUser);
            resp.setDispatchPatrons(wildUserMsg);
        }
        int unionRank = CrossStrongholdRankMgr.getCrossActivityUnionRank(activityId, eGamePlayerEventType.StrongholdWildUnionScoreRank.getValue(), serverId, unionUid);
        int myRank = CrossStrongholdRankMgr.getCrossActivityRank(activityId, eGamePlayerEventType.StrongholdWildScoreRank.getValue(), serverId, userId);
        resp.setPersonalRank(myRank);
        resp.setUnionRank(unionRank);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(GameProtocol.S_CROSS_STRONGHOLD_WILD_LIST, resp);
        MessageHelper.sendPacket(serverId, userId, pbMsg);

    }

    @Override
    public void sendData() {

    }
}
